import pygame as pg
from pygame.locals import *
from costants import *
##########################################################
##########################################################
try: font=pygame.font.Font(FONT,FONT_DIM)
except IOError: font=pygame.font.Font(ALTERNATIVE_FONT,FONT_DIM)
##########################################################
##########################################################
class Player:
	def __init__(self,name,score):
		self.name=name
		self.name_img=font.render(name,True,SCORE_COLOR)
		self.score=score
		self.deleted_lines=0
		self.game=None
		self.remaining_balls=0
		
	def starting_game(self,game):
		self.game=game
	
	def ball_lost(self):
		self.remaining_balls-=1
		
	def blit(self,screen):
		if self.game==TETRIS:
			screen.blit(self.name_img,NAME_TETRIS_RECT)
			self.score.blit(screen)
		if self.game==ARK:
			screen.blit(self.name_img,ARK_NAME_POS)
			if self.remaining_balls==1:
				img=pg.image.load(ONE_BALL).convert_alpha()
				screen.blit(img,ARK_BALL_POS)
			if self.remaining_balls==2:
				img=pg.image.load(TWO_BALL).convert_alpha()
				screen.blit(img,ARK_BALL_POS)
			if self.remaining_balls==3:
				img=pg.image.load(THREE_BALL).convert_alpha()
				screen.blit(img,ARK_BALL_POS)
	
	def pass_level(self):
		if self.deleted_lines>=LINES_TO_DEL:
			self.deleted_lines=0
			return True
		else: return False
	
	def increase_deleted_lines(self,lines):
		self.deleted_lines +=lines
		if lines>0: self.score.increase(lines)
##########################################################
class Score:
	def __init__(self):
		self.score=0
		
	def increase(self,deleted_lines):
		self.score+=100*deleted_lines+50*(deleted_lines-1)
		
	def to_half(self):
		self.score=self.score/2
		
	def to_double(self):
		self.score=self.score*2
		
	def blit(self,screen):
		img=font.render('Score:  '+str(self.score), True, SCORE_COLOR)
		screen.blit(img,SCORE_RECT)
##########################################################
##########################################################
